//模态框居中 myModal：模态框id
function centerModals(myModal) {
    // 关键代码，如没将modal设置为 block，则$modala_dialog.height() 为零
    $('#' + myModal).css('display', 'block');
    var modalHeight = $(window).height() / 2 - $('#' + myModal + ' .modal-dialog').height() / 2;
    $('#' + myModal).find('.modal-dialog').css({
        'margin-top': modalHeight
    });
}

//弹出框样式
function promptMsg(str, url) {
    //弹框节点存在则不再提醒，防止由于多次弹框导致弹框无法消失的问题
    if ($("#alertFram").length > 0) {
        return;
    }
    //创建底层div(遮罩)
    var shield = document.createElement("DIV");
    //设置div的属性
    shield.id = "shield";
    shield.style.position = "absolute";
    shield.style.left = "0px";
    shield.style.top = "0px";
    shield.style.width = "100%";
    shield.style.height = "100%";
    //弹出对话框时的背景颜色
    shield.style.background = "#111";
    shield.style.textAlign = "center";
    shield.style.zIndex = "25000";
    shield.style.opacity = "0.4";
    //创建提示框div
    var alertFram = document.createElement("DIV");
    //设置div属性
    alertFram.id = "alertFram";
    alertFram.style.position = "absolute";
    alertFram.style.left = "50%";
    alertFram.style.top = "40%";
    alertFram.style.marginLeft = "-200px";
    alertFram.style.width = "400px";
    alertFram.style.height = "180px";
    alertFram.style.background = "#EF5F21;";
    alertFram.style.textAlign = "center";
    alertFram.style.zIndex = "25001";
    //设置显示部分div结构
    var strHtml = "<div style='padding: 2px 15px;background-color:#0077d4;text-align: left;color:#fff;font-weight:300'><h6 style='font-size:15px;margin:11px 0;'>消息提醒</h6></div>"
    strHtml += "<div style='background-color:#fff;text-align:left;padding:15px;word-wrap:break-word;'><h4>" + str + "</h4></div>"
    strHtml += "<div style='padding: 14px 15px 15px;background-color:#f5f5f5;text-align:right'><button id='alert_button' class='form-btn-modal-ok' type='button' onclick='doOk()'>确定</button></div>"
    //提示框结构加入第二层div
    alertFram.innerHTML = strHtml;
    //把第一层遮罩和第二层显示层div加入到页面元素中
    document.body.appendChild(alertFram);
    document.body.appendChild(shield);
    //禁止页面选中
    document.body.onselectstart = function () {
        return false;
    };
    //确定按钮获取焦点
    $(".alert_button").focus();
    //点击确定方法
    this.doOk = function () {
        alertFram.style.display = "none";
        shield.style.display = "none";
        //恢复页面选中
        document.body.onselectstart = function () {
            return true;
        }
        //删掉节点，防止出现多次弹框
        $("#alertFram").remove();
        //页面跳转问题解决
        if (url != undefined) {
            window.location.href = url;
        }
    }
}

//确认提示框
//msg：提示消息
//yesCallBack：点击确定需要执行的函数(不可为null,必须传函数)
//noCallBack：点击取消需要执行的函数（可传null）
function confirmMsg(msg, yesCallBack, noCallBack) {
    var message = msg || "确认删除此条信息?";

    var choose = function (tag) {
        return document.querySelector(tag);
    }
    choose(".dialog-message").innerHTML = "<h4>" + message + "</h4>";
    //模态框居中： 将事件监听的事件改成show.bs.modal 即可解决
    $('#confirmDivModal').on('show.bs.modal', centerModals("confirmDivModal"));
    $("#confirmDivModal").modal({
        backdrop: "static",//点击空白处不关闭对话框
        keyboard:false // 按esc键盘不关闭
    });

    choose("#dialog").onclick = function (e) {
        if (e.target.className == "form-btn-modal-ok") {
            // 确定按钮
            yesCallBack();
            $("#confirmDivModal").modal("hide");
        } else if (e.target.className == "form-btn-modal-cancel") {
            // 取消按钮
            if (noCallBack != null) {
                noCallBack();
            }
            $("#confirmDivModal").modal("hide");
        }
    };
}

//弹出框自定义样式（样式仿照alert，在手册维护编辑时用）
window.alert_noButton = function (str, url) {
    //创建底层div(遮罩)
    var shield = document.createElement("DIV");
    //设置div的属性
    shield.id = "shield";
    shield.style.position = "absolute";
    shield.style.left = "0px";
    shield.style.top = "0px";
    shield.style.width = "100%";
    shield.style.height = "100%";
    //弹出对话框时的背景颜色
    shield.style.background = "#111";
    shield.style.textAlign = "center";
    shield.style.zIndex = "25000";
    shield.style.opacity = "0.4";
    //创建提示框div
    var alertFram = document.createElement("DIV");
    //设置div属性
    alertFram.id = "alertFram";
    alertFram.style.position = "absolute";
    alertFram.style.left = "50%";
    alertFram.style.top = "40%";
    alertFram.style.marginLeft = "-200px";
    alertFram.style.width = "400px";
    alertFram.style.height = "180px";
    alertFram.style.background = "#EF5F21;";
    alertFram.style.textAlign = "center";
    alertFram.style.zIndex = "25001";
    //设置显示部分div结构
    var strHtml = "<div style='padding: 2px 15px;background-color:#0077d4;text-align: left;color:#fff;font-weight:300'><h6 style='font-size:15px;margin:11px 0;'>消息提醒</h6></div>"
    strHtml += "<div style='background-color:#fff;text-align:left;padding:15px;'><h4>" + str + "</h4></div>"
    strHtml += "<div style='padding: 14px 15px 15px;background-color:#f5f5f5;text-align:right;height:45px;'></div>"
    //提示框结构加入第二层div
    alertFram.innerHTML = strHtml;
    //把第一层遮罩和第二层显示层div加入到页面元素中
    document.body.appendChild(alertFram);
    document.body.appendChild(shield);
    //禁止页面选中
    document.body.onselectstart = function () {
        return false;
    };
    //确定按钮获取焦点
    $(".alert_button").focus();
    //点击确定方法
    this.doOk_noButton = function () {
        alertFram.style.display = "none";
        shield.style.display = "none";
        //恢复页面选中

        document.body.onselectstart = function () {
            return true;
        }

        //页面跳转问题解决
        if (url != undefined) {
            window.location.href = url;
        }
    }
}

//自定义confirm部分（样式仿照alert，在手册维护编辑时用）
//msg：提示消息
//yesCallBack：点击确定需要执行的函数(不可为null,必须传函数)
//noCallBack：点击取消需要执行的函数（可传null）
window.confirm_alert = function (msg, yesCallBack, noCallBack) {
    var message = msg;

    var choose = function (tag) {
        return document.querySelector(tag);
    }
    choose(".dialog-alert-message").innerHTML = "<h4>" + message + "</h4>";
    //模态框居中： 将事件监听的事件改成show.bs.modal 即可解决
    $('#confirmAlertDivModal').on('show.bs.modal', centerModals("confirmAlertDivModal"));
    $("#confirmAlertDivModal").modal({
        backdrop: "static",//点击空白处不关闭对话框
        keyboard:false // 按esc键盘不关闭
    });

    choose("#dialog_alert").onclick = function (e) {
        if (e.target.className == "form-btn-modal-cancel") {
            // 确定按钮
            yesCallBack();
            $("#confirmAlertDivModal").modal("hide");
        }
    };
}